module technical
implicit none
public 
integer,parameter :: labellen=100
double precision, parameter :: pi=4.*datan(1.0d0)
double complex, parameter :: zi = (0.,1.)
contains
!======================
  subroutine announce(location,message)
!
    character(len=*) :: location
    character(len=*) :: message
    
    write(*,*)'NOTE: ',location,' ',message
   
endsubroutine announce
!======================
  subroutine log_message(message)
!
    character(len=*) :: message
    
    write(*,*)'log:','',message
   
endsubroutine log_message
!======================
  subroutine fatal_error(location,message)
!
    character(len=*) :: location
    character(len=*) :: message
    
    write(*,*)'FATAL ERROR: ',location,' ',message
    STOP 1
endsubroutine fatal_error
!========================
  subroutine warning(location,message)
!
    character(len=*) :: location
    character(len=*) :: message
    
    write(*,*)'WARNING',location,message
    write(*,*)'will however proceed'
endsubroutine warning
!==========================
function count_lines(file)
!
!code borrwoed from pencil-code
!
  character(len=*) :: file
  integer :: count_lines
!
  integer :: unit=1, ierr
!
  count_lines=-1
  if (.not. file_exists(file)) then
     call announce(file,'not found')
  call fatal_error('count lines:','file not found')
  endif
!
  count_lines=0
  open(unit, FILE=file, STATUS='old', IOSTAT=ierr)
  if (ierr/=0) return
  do while (ierr.eq.0)
     read(unit,*,iostat=ierr)
      if (ierr.eq.0) count_lines=count_lines+1
  enddo
  close(unit)
!
endfunction count_lines
!============================================
function file_exists(file,delete)
!
!  code copied from pencil-code
!
  logical :: file_exists
  character(len=*) :: file
  logical, optional :: delete
!
  integer :: unit=1
!
  inquire(file=file, exist=file_exists)
!
  if (file_exists .and. present(delete)) then
     if (delete) then
        call announce('technical: removing file', file)
        open(unit,FILE=file)
        close(unit,STATUS='DELETE')
     endif
  endif
!
endfunction file_exists
!============================================
subroutine stop_it(msg)
  character (len=*) :: msg  
  write(*,*) 'STOPPED:',msg
  STOP 1
endsubroutine stop_it
!============================================
end module technical
